//index.js
//获取应用实例
const app = getApp()

Page({
    data: {
        swiper: [
            'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3495514660,2986887290&fm=26&gp=0.jpg',
            'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2929458141,3230547596&fm=200&gp=0.jpg',
            'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3301034990,2876024777&fm=26&gp=0.jpg'
        ],
        tabs: ["全部", "进行中", "已完成"],
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),

        name:'',
        phone:'',
        eva:'',

        isClick:0,
        status:0,
    },
    //事件处理函数
    bindViewTap: function () {
        wx.navigateTo({
            url: '../logs/logs'
        })
    },
    onLoad: function (options) {
        var obj = {};
        if(options && options.status){
            obj.status = options.status;
            this.setData({
                status:options.status
            })

        }
        this.getAuthInfo();
    },
    submitAuth:function () {
        var that = this;

        if(that.data.isClick || that.data.status == 1 || that.data.status == 3) return;
        that.data.isClick = 1;

        var reg = /^1[3-9][0-9]{9}$/;
        var checkPhone = reg.test(this.data.phone)
        if(!checkPhone){
            wx.showModal({
                title:'提示',
                content:'请检查手机号码格式',
                showCancle:false,
            });
            that.data.isClick = 0;
            return;
        }
        if(!this.data.name || !this.data.phone || !this.data.eva){
            wx.showModal({
                title:'提示',
                content:'数据不完整，检查后再提交',
                showCancle:false,
            })
            that.data.isClick = 0;
            return;
        }
        var data = {
            name:that.data.name,
            telphone:that.data.phone,
            self_evaluation:that.data.eva
        }
        wx.showToast({
            title:'加载中',
            icon:'loading'
        })
        app.util.request({
            url:app.globalRequestUrl + '/saddauth',
            method:'GET',
            data:data,
            success:function (res) {
                if(res && res.msg == 'success'){
                    wx.showToast({
                        title:'提交成功！',
                        icon:'success'
                    });
                    wx.setStorageSync('name',that.data.name)
                    wx.setStorageSync('phone',that.data.phone)
                    wx.setStorageSync('eva',that.data.eva)

                    setTimeout(function () {
                        wx.switchTab({
                            url:'/pages/my/my'
                        })
                    },2000)
                }
            },
            complete:function () {
                wx.hideToast();
                setTimeout(function () {
                    that.data.isClick = 0;
                },1000)
            }
        })
    },
    getAuthInfo:function(){
        var that = this;
        wx.showToast({
            title:'加载中',
            icon:'loading'
        })
        app.util.request({
            url:app.globalRequestUrl + '/authshow',
            method:'GET',
            success:function (res) {
                if(res && res.msg == 'success' && res.data){
                    that.setData({
                        name:res.data.name,
                        phone:res.data.telphone,
                        eva:res.data.self_evaluation
                    })
                }
            },
            complete:function () {
                wx.hideToast();
            }
        })
    },
    bindInputName:function (e) {
        this.data.name = e.detail.value;
    },
    bindInputPhone:function (e) {
        this.data.phone = e.detail.value;

    },
    bindInputEva:function (e) {
        this.data.eva = e.detail.value;

    },
    navigateToMy:function () {
        wx.switchTab({
            url:'/pages/my/my'
        })
    }
})
